package com.jjlin.chapter_5;

import java.util.*;

public class CD116{

    public static void reverse(char[] chars, int start, int end){
        while(start < end){
            char tmp = chars[start];
            chars[start++] = chars[end];
            chars[end--] = tmp;
        }
    }

    //翻转字符串(1)
    public static void rotateWord(char[] chars){
        if(chars == null || chars.length < 1)
            return;
        int l = -1, r = -1, n = chars.length;
        for(int i = 0; i < n; i++){
            if(chars[i] != ' '){
                l = i == 0 || chars[i - 1] == ' ' ? i : l;
                r = i == n - 1 || chars[i + 1] == ' ' ? i : r;
            }
            if(l != -1 && r != -1){
                reverse(chars, l, r);
                l = -1;
                r = -1;
            }
        }
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        char[] chars = str.toCharArray();
        rotateWord(chars);
        for(int i = 0; i < chars.length; i++)
            System.out.print(chars[i]);
    }
}
